package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.AdminDto;
import com.qs.pojo.dto.BrandDto;
import com.qs.pojo.entity.Admin;
import com.qs.pojo.entity.Brand;
import com.qs.response.Response;
import com.qs.service.IBrandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌管理表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-12
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/brand")
@RequiredArgsConstructor
public class BrandController {

    private final IBrandService brandService;

    /**
     * 获取品牌管理分页数据
     * @param pageNo
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable Integer pageNo,
                         @PathVariable Integer pageSize,
                         String name) {
        log.info("获取品牌管理分页数据请求进来--------------------");
        Map<String,Object> brandMap = brandService.getList(pageNo,pageSize,name);
        return Response.success(brandMap);
    }

    /**
     * 新增品牌
     * @param brand
     * @return
     */
    @PostMapping("/save")
    @OperationLog(operModul = "品牌管理-新增品牌",operDesc = "管理员新增商品品牌")
    public Response saveBrand(@RequestBody Brand brand) {
        log.info("新增品牌请求进来--------------------");
        brandService.saveBrand(brand);
        return Response.success();
    }

    /**
     * 修改品牌
     * @param
     * @param
     * @param
     * @return
     */
    @PutMapping("/update")
    @OperationLog(operModul = "品牌管理-修改品牌",operDesc = "管理员修改商品品牌")
    public Response update(@RequestBody BrandDto brandDto) {
        log.info("修改品牌请求进来--------------------");
        brandService.updateByKey(brandDto);
        return Response.success();
    }

    /**
     * 品牌管理数据回显
     * @param
     * @param
     * @param
     * @return
     */
    @GetMapping("/getById/{id}")
    public Response echo(@PathVariable Integer id) {
        log.info("品牌管理数据回显请求进来--------------------");
        BrandDto brandDto = brandService.echo(id);
        return Response.success(brandDto);
    }

    /**
     * 删除品牌
     * @param
     * @param
     * @param
     * @return
     */
    @DeleteMapping("/remove/{ids}")
    @OperationLog(operModul = "品牌管理-删除品牌",operDesc = "管理员删除商品品牌")
    public Response delete(@PathVariable List<Integer> ids) {
        log.info("删除品牌请求进来--------------------");
        brandService.delete(ids);
        return Response.success();
    }
}
